package com.dxf.bigdata.D05_spark_again

import org.apache.spark.{SparkConf, SparkContext}

/**
 * map 的带index序号 多分区并发
 */
object MapPartitions_Index {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")

    val sc = new SparkContext(sparkConf)

    val list = sc.makeRDD(List(1, 23, 4, 5, 6), 2)

    val value = list.mapPartitionsWithIndex(
      (index, iter) => {

        if (index == 1) {
          iter
        } else {
          Nil.iterator
        }

      }
    )

    value.collect().foreach(println)


  }

}
